﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

// Pour en savoir plus sur le modèle d'élément Contrôle utilisateur, consultez la page http://go.microsoft.com/fwlink/?LinkId=234236

namespace InterfaceXAML.UserControls
{
    public sealed partial class RadioButtonList : UserControl
    {

        public Object ItemsSource
        {
            get ;
            set ;
        }

        public int SelectedIndex
        {
            get { return ListBox.SelectedIndex; }
            set { ListBox.SelectedIndex = value; }
        }

        public Object SelectItem
        {
            get { return ListBox.SelectedItem; }
            set { ListBox.SelectedItem = value; }
        }

        public String GroupName
        {
            get;
            set;
        }

        public static readonly DependencyProperty ItemsSourceProperty = DependencyProperty.Register("ItemsSource", typeof(Object), typeof(RadioButtonList), new PropertyMetadata(null, OnItemsSourceChanged));
        
        public RadioButtonList()
        {
            this.InitializeComponent();
        }

        private static void OnItemsSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var value = e.NewValue;
            var currentControl = d as RadioButtonList;
            currentControl.ListBox.ItemsSource = value;
        }

        public void DisplayError()
        {
            BorderWrapper.BorderBrush = Application.Current.Resources["ErrorField"] as SolidColorBrush;
            BorderWrapper.BorderThickness = new Thickness(2);
        }

        public void DisplayNormal()
        {
            BorderWrapper.BorderBrush = new SolidColorBrush(Colors.Transparent);
            BorderWrapper.BorderThickness = new Thickness(0);
        }

    }
}
